function init() {
	http_request = false;
	mime_type = 'text/html';
	//mime_type = 'text/xml';
}
 
function get(obj, url, callback) {
	var formVars = '';
	if (obj) formVars = serializeFormVars(obj);
  makeRequest('GET', url, formVars, callback);
}

function post(obj, url, callback) {
	var formVars = '';
	if (obj) formVars = serializeFormVars(obj);
  makeRequest('POST', url, formVars, callback);
}

function makeRequest(requestMethod, url, parameters, callback) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			http_request.overrideMimeType(mime_type);
		 }
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			  http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
		
	http_request.onreadystatechange = function() { 		
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				//alert(http_request.responseText);
				result = http_request.responseText;
				if (callback) { 
					callback(result); 
				}
			} else {
				alert('There was a problem with the request: ' + http_request.status);
			}
		}
	} 
	
	http_request.open(requestMethod, url, callback ? true : false);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function serializeFormVars(obj) {
	var getstr = "?";
  for (i=0; i<obj.getElementsByTagName("input").length; i++) {
    if (obj.getElementsByTagName("input")[i].type == "text" || 
				obj.getElementsByTagName("input")[i].type == "hidden") {
    	getstr += obj.getElementsByTagName("input")[i].name + "=" + 
        obj.getElementsByTagName("input")[i].value + "&";
    }
    if (obj.getElementsByTagName("input")[i].type == "checkbox") {
      if (obj.getElementsByTagName("input")[i].checked) {
        getstr += obj.getElementsByTagName("input")[i].name + "=" + 
           obj.getElementsByTagName("input")[i].value + "&";
      } else {
        getstr += obj.getElementsByTagName("input")[i].name + "=&";
      }
    }
    if (obj.getElementsByTagName("input")[i].type == "radio") {
      if (obj.getElementsByTagName("input")[i].checked) {
        getstr += obj.getElementsByTagName("input")[i].name + "=" + 
          obj.getElementsByTagName("input")[i].value + "&";
      }
    }  
    if (obj.getElementsByTagName("input")[i].tagName == "SELECT") {
      var sel = obj.getElementsByTagName("input")[i];
      getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
    }     
  }
	return getstr;
}

init();